'''
    1.实现开户模块接口的测试用例
'''
import unittest
import requests

import utils
from api.api_open_account import OpenAccountApi
from api.api_reg_login import RegLoginApi


class TestOpenAccount(unittest.TestCase):

    def setUp(self) -> None:
        # 创建session对象
        self.session = requests.session()
        # 实例化开户模块封装的类
        self.api_open_account = OpenAccountApi(self.session)
        # 实例化登录模块封装的类
        self.api_reg_login = RegLoginApi(self.session)
        # 调用登录接口，完成用户登录
        self.api_reg_login.user_login("18800011121", "123qqq")

    def tearDown(self) -> None:
        # 关闭session对象
        self.session.close()

    # 实名认证测试用例
    def test01_realname(self):
        res = self.api_open_account.realname("张三", "110101199003071516")
        print(res.json())

    # 查询实名认证信息测试用例
    def test02_query_realname(self):
        pass

    # 开户测试用例
    def test03_open_account(self):
        res = self.api_open_account.open_account()
        print(res.json())

    # 第三方开户测试用例
    def test04_third_open_account(self):
        # 调用开户接口
        res_open_account = self.api_open_account.open_account()
        # 获取第三方开户接口的url
        url = utils.html_util(res_open_account)[0]
        # 获取第三方开户接口的请求体数据
        data_form = utils.html_util(res_open_account)[1]
        # 获取第三方接口返回的响应结果
        res_third_open_account = self.api_open_account.third_open_account(url, data_form)
        print(res_third_open_account.text)
        # 断言
        self.assertIn("OK", res_third_open_account.text)
